﻿using MySchool;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyKTV.wxt
{
    public partial class Form000003 : Form
    {

        public string box0 { get; internal set; }
        public string box1 { get; internal set; }
        public string box2 { get; internal set; }
        public string box3 { get; internal set; }
        public string box4 { get; internal set; }
        public string box5 { get; internal set; }
        public string box6 { get; internal set; }
        public string box7 { get; internal set; }
        DBHelper db = new DBHelper();
        DataSet ds = new DataSet();
        public Form000003()
        {
            InitializeComponent();
        }
        string l;
        private void button2_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text.Trim() == "")
            {
                MessageBox.Show("修改名字不能为空");
                return;
            }


            db.OpenConnection();


            int conn = 0;

            if (this.comboBox1.Text == "热门流行")
            {
                conn = 1;
            }
            else if (this.comboBox1.Text == "经典老歌")
            {
                conn = 2;
            }
            else if (this.comboBox1.Text == "影视金曲")
            {
                conn = 3;
            }
            else if (this.comboBox1.Text == "游戏动漫")
            {
                conn = 4;
            }
            else if (this.comboBox1.Text == "京剧戏曲")
            {
                conn = 5;
            }
            else if (this.comboBox1.Text == "儿歌")
            {
                conn = 6;
            }

            if (conn == 0)
            {
                MessageBox.Show("请输入正确的歌曲类型");
                return;
            }




            string str = "update song_info set song_name=N'" + this.textBox1.Text + "',song_ab=N'" + this.textBox2.Text + "',song_word_count=N'" + this.textBox3.Text + "'" +
                ",songtype_id=N'" + conn + "',singer_id=N'" + this.comboBox2.SelectedValue + "',song_url=N'" + this.textBox4.Text + "',song_play_count=N'" + this.textBox5.Text + "' where song_id =N'" +17+ "'";
            SqlCommand comm = new SqlCommand(str, db.Connection);
            int pd = comm.ExecuteNonQuery();
            if (pd > 0)
            {
             
                MessageBox.Show("修改成功");
                textBox1.Text = null;
                textBox5.Text = null;
                textBox4.Text = null;

            }
            else
            {
                MessageBox.Show("修改失败");
            }

        }

        private void Form000003_Load(object sender, EventArgs e)
        {
            db.OpenConnection();
            this.textBox1.Text = box1;
            this.textBox2.Text = box2;
            this.textBox3.Text = box3;
            this.comboBox1.Text = box4;
            this.textBox4.Text = box6;
            this.textBox5.Text = box7;


            string str = "select * from singer_info";
            SqlDataAdapter adapter = new SqlDataAdapter(str, db.Connection);
            adapter.Fill(ds, "singer_info");
            this.comboBox2.DataSource = ds.Tables["singer_info"];

            this.comboBox2.ValueMember = "singer_id";
            this.comboBox2.DisplayMember = "singer_name";

            comboBox2.Text = box5;


        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog2 = new OpenFileDialog();
            openFileDialog2.Multiselect = true;  //该值确定是否可以选择多个文件
            openFileDialog2.Title = "请选择文件";
            openFileDialog2.Filter = "音乐(*.mp3)|*.mp3";
            //openFileDialog2.Filter = "文档(*.doc;*.docx)|*.doc;*.docx";
            if (openFileDialog2.ShowDialog() == DialogResult.OK)
            {
                if (openFileDialog2.FileName != "")
                {
                    l = openFileDialog2.FileName;
                    textBox4.Text = l.Substring(openFileDialog2.FileName.LastIndexOf("\\") + 1);
                }
            }
        }

        private void label8_Click(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
